import 'package:flutter/material.dart';
import 'package:x3_charts_core/chart_painter/two_way_bar_chart_painter.dart';
import 'package:x3_charts_core/model/two_way_bar_chart_model.dart';

///**
///* @author hrongyong
///* @date   2/4/21
///* @email hrongyong@gmail.com
///* Description:  双向横条图
///*/
class TwoWayBarChartWidget extends StatefulWidget {
  ///左边数据
  final List<TwoWayBarChartModel> leftList;

  ///右边数据
  final List<TwoWayBarChartModel> rightList;

  ///左边颜色
  final Color leftColors;

  ///右边颜色
  final Color rightColors;

  TwoWayBarChartWidget({@required this.leftList, @required this.rightList, this.leftColors = const Color(0xFFFFE3D8), this.rightColors = const Color(0xFF48AACA)});

  @override
  _TwoWayBarChartWidgetState createState() => _TwoWayBarChartWidgetState();
}

class _TwoWayBarChartWidgetState extends State<TwoWayBarChartWidget> with SingleTickerProviderStateMixin {
  AnimationController _controller;

  @override
  void initState() {
    super.initState();
    _controller = AnimationController(
      duration: const Duration(milliseconds: 1000),
      vsync: this,
    )..forward();
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      child: LayoutBuilder(
        builder: (BuildContext context, BoxConstraints constraints) {
          return CustomPaint(
            size: Size(constraints.maxWidth, constraints.maxHeight),
            painter: TwoWayBarChartPainter(leftList: widget.leftList, leftColors: widget.leftColors, rightList: widget.rightList, rightColors: widget.rightColors, repaint: _controller),
          );
        },
      ),
    );
  }


}
